<!-- @format -->

<template>
  <view class="badge-example">
    <text class="example-title">徽标组件示例</text>

    <!-- 基础用法 -->
    <view class="example-section">
      <text class="section-title">基础用法</text>
      <view class="badge-row">
        <comp-badge :value="5">
          <view class="badge-item">徽标</view>
        </comp-badge>
        <comp-badge :value="10">
          <view class="badge-item">徽标</view>
        </comp-badge>
        <comp-badge :value="100">
          <view class="badge-item">徽标</view>
        </comp-badge>
        <comp-badge value="NEW">
          <view class="badge-item">徽标</view>
        </comp-badge>
      </view>
    </view>

    <!-- 小红点 -->
    <view class="example-section">
      <text class="section-title">小红点</text>
      <view class="badge-row">
        <comp-badge dot>
          <view class="badge-item">小红点</view>
        </comp-badge>
      </view>
    </view>

    <!-- 最大值 -->
    <view class="example-section">
      <text class="section-title">最大值</text>
      <view class="badge-row">
        <comp-badge :value="20" :max="9">
          <view class="badge-item">最大值9</view>
        </comp-badge>
        <comp-badge :value="50" :max="20">
          <view class="badge-item">最大值20</view>
        </comp-badge>
        <comp-badge :value="200" :max="99">
          <view class="badge-item">最大值99</view>
        </comp-badge>
      </view>
    </view>

    <!-- 自定义颜色 -->
    <view class="example-section">
      <text class="section-title">自定义颜色</text>
      <view class="badge-row">
        <comp-badge :value="5" color="#1989fa">
          <view class="badge-item">自定义颜色</view>
        </comp-badge>
        <comp-badge :value="10" color="#ff8c00" text-color="#fff">
          <view class="badge-item">自定义颜色</view>
        </comp-badge>
        <comp-badge dot color="#52c41a">
          <view class="badge-item">自定义颜色</view>
        </comp-badge>
      </view>
    </view>

    <!-- 徽标类型 -->
    <view class="example-section">
      <text class="section-title">徽标类型</text>
      <view class="badge-row">
        <comp-badge :value="5" type="primary">
          <view class="badge-item">主要</view>
        </comp-badge>
        <comp-badge :value="5" type="success">
          <view class="badge-item">成功</view>
        </comp-badge>
        <comp-badge :value="5" type="warning">
          <view class="badge-item">警告</view>
        </comp-badge>
        <comp-badge :value="5" type="danger">
          <view class="badge-item">危险</view>
        </comp-badge>
        <comp-badge :value="5" type="info">
          <view class="badge-item">信息</view>
        </comp-badge>
      </view>
    </view>

    <!-- 徽标尺寸 -->
    <view class="example-section">
      <text class="section-title">徽标尺寸</text>
      <view class="badge-row">
        <comp-badge :value="5" size="small">
          <view class="badge-item">小号</view>
        </comp-badge>
        <comp-badge :value="5" size="medium">
          <view class="badge-item">中号</view>
        </comp-badge>
        <comp-badge :value="5" size="large">
          <view class="badge-item">大号</view>
        </comp-badge>
      </view>
    </view>

    <!-- 独立使用 -->
    <view class="example-section">
      <text class="section-title">独立使用</text>
      <view class="badge-row">
        <comp-badge :value="5" />
        <comp-badge :value="10" type="primary" />
        <comp-badge value="Hot" type="warning" />
        <comp-badge dot type="success" />
      </view>
    </view>

    <!-- 带边框 -->
    <view class="example-section">
      <text class="section-title">带边框</text>
      <view class="badge-row">
        <comp-badge :value="5" bordered>
          <view class="badge-item badge-item--dark">带边框</view>
        </comp-badge>
        <comp-badge :value="10" type="primary" bordered>
          <view class="badge-item badge-item--dark">带边框</view>
        </comp-badge>
        <comp-badge dot type="success" bordered>
          <view class="badge-item badge-item--dark">带边框</view>
        </comp-badge>
        <comp-badge value="99+" bordered border-color="#ffd591">
          <view class="badge-item badge-item--dark">自定义边框色</view>
        </comp-badge>
      </view>
    </view>

    <!-- 自定义徽标内容 -->
    <view class="example-section">
      <text class="section-title">自定义徽标内容</text>
      <view class="badge-row">
        <comp-badge>
          <view class="badge-item">自定义内容</view>
          <template #badge>
            <text class="custom-badge">NEW</text>
          </template>
        </comp-badge>
        <comp-badge>
          <view class="badge-item">自定义内容</view>
          <template #badge>
            <text class="custom-badge custom-badge--hot">HOT</text>
          </template>
        </comp-badge>
      </view>
    </view>

    <!-- 可隐藏的徽标 -->
    <view class="example-section">
      <text class="section-title">可隐藏的徽标</text>
      <view class="badge-row">
        <comp-badge :value="hideValue ? 5 : 0" :hidden="!hideValue">
          <view class="badge-item">{{ hideValue ? '显示徽标' : '隐藏徽标' }}</view>
        </comp-badge>
        <button class="toggle-button" @click="toggleBadge">切换显示状态</button>
      </view>
    </view>

    <!-- 应用场景示例 -->
    <view class="example-section">
      <text class="section-title">应用场景示例</text>
      <view class="app-example">
        <view class="tab-bar">
          <view class="tab-item">
            <view class="tab-icon">🏠</view>
            <text class="tab-text">首页</text>
          </view>
          <view class="tab-item">
            <comp-badge :value="12" :max="99">
              <view class="tab-icon">📝</view>
            </comp-badge>
            <text class="tab-text">消息</text>
          </view>
          <view class="tab-item">
            <comp-badge dot>
              <view class="tab-icon">🛒</view>
            </comp-badge>
            <text class="tab-text">购物车</text>
          </view>
          <view class="tab-item">
            <view class="tab-icon">👤</view>
            <text class="tab-text">我的</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import CompBadge from './Index.vue';

// 控制徽标显示/隐藏
const hideValue = ref(true);

// 切换徽标显示状态
const toggleBadge = () => {
  hideValue.value = !hideValue.value;
};
</script>

<style lang="scss" scoped>
.badge-example {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;

  .example-title {
    font-size: 24px;
    margin-bottom: 20px;
    color: #333;
    display: block;
  }

  .example-section {
    margin-bottom: 30px;

    .section-title {
      font-size: 18px;
      margin-bottom: 10px;
      color: #666;
      display: block;
    }

    .badge-row {
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      margin-bottom: 10px;
    }
  }

  .badge-item {
    width: 80px;
    height: 40px;
    background-color: #f7f8fa;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #646566;

    &--dark {
      background-color: #323233;
      color: #fff;
    }
  }

  .toggle-button {
    padding: 8px 16px;
    background-color: #1989fa;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 14px;
  }

  .custom-badge {
    padding: 0 6px;
    background-color: #1989fa;
    color: #fff;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.2;

    &--hot {
      background-color: #ff976a;
    }
  }

  .app-example {
    border: 1px solid #eee;
    padding: 20px;
    border-radius: 8px;

    .tab-bar {
      display: flex;
      justify-content: space-around;
      align-items: center;
      height: 50px;
      background-color: #fff;
      border-top: 1px solid #eee;
    }

    .tab-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    .tab-icon {
      font-size: 24px;
      margin-bottom: 4px;
      position: relative;
    }

    .tab-text {
      font-size: 12px;
      color: #646566;
    }
  }
}
</style>